//
//  UIImageView+networkImage.m
//  physicalProject
//
//  Created by Westbrook on 2018/5/22.
//  Copyright © 2018年 cjkt. All rights reserved.
//

#import "UIImageView+networkImage.h"

#import <UIImageView+WebCache.h>


@implementation UIImageView (networkImage)

- (void)drawCircle {
    
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:self.bounds.size];
    
    CAShapeLayer *maskLayer = [CAShapeLayer layer];
    maskLayer.frame = self.bounds;
    maskLayer.path = maskPath.CGPath;
    self.layer.mask = maskLayer;
    
}

- (void)loadNetworkImage:(NSString *_Nullable)imageUrl placeHolderImage:(NSString *_Nullable)placeHolderImageName{
    
    [self sd_setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:[UIImage imageNamed:placeHolderImageName]];
    
}

- (void)loadNetworkBigImage:(NSString *_Nullable)imageUrl {
    
    [self loadNetworkImage:imageUrl placeHolderImage:@"bigPlaceholder"];
    
}

- (void)loadNetworkSmallImage:(NSString *_Nullable)imageUrl {
    
    [self loadNetworkImage:imageUrl placeHolderImage:@"smallPlaceholder"];
    
}

- (void)loadNetworkImageWithCompletion:(NSString *_Nullable)imageUrl placeHolderImage:(NSString *_Nullable)placeHolderImageName completion:(void (^_Nullable)(UIImage * _Nullable image,NSURL * _Nullable imageURL))completion {
    
    [self sd_setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:[UIImage imageNamed:placeHolderImageName] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        
        completion(image, imageURL);
        
    }];
    
}


@end
